package com.A1908.servlet;

import com.A1908.entity.RelationType;
import com.A1908.service.RelationService;
import com.A1908.service.impl.RelationServiceImpl;
import com.alibaba.fastjson.JSON;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

@WebServlet(urlPatterns = {"/rType"})
public class RelationTypeServlet extends HttpServlet {
    RelationService relationService = new RelationServiceImpl();

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=UTF-8");
        String opr = request.getParameter("opr");
        PrintWriter out = response.getWriter();

        if ("list".equals(opr) || opr == null){
            List<RelationType> list = relationService.findAllRelationInfo();
            out.print(JSON.toJSONString(list));
        }
        out.close();
    }
}
